import { Injectable } from '@angular/core';
import { Http, Response, Headers } from '@angular/http';
import 'rxjs/add/operator/map';
import 'rxjs/Rx';

@Injectable()
export class DataService {
  constructor(private http: Http) {

  }

  getLiveCover(callback = undefined,errorCallback =undefined) {

      var url = 'http://app2.me-to-me.com/api/live/liveCover';
    //  var url = 'http://192.168.89.205:8080/api/live/liveTimeline';
     var body = "uid=295&token=76cfdad8ebe94ef9abe6b1e0fa3695e3&appId=110202&topicId=1317&sinceId=0&security={\"appId\":\"100201\",\"currentTime\":\"1471077216791\",\"nonce\":\"043eb17ae3eb4bc09407e63b3bb10a12\",\"sign\":\"aa35ad90185ba7760a9a9bd2b587610af385a761\"}"
      var headers = new Headers();
      
    var body_mask = JSON.stringify(body);
    console.info(body_mask);
    headers.append('Content-Type', 'application/x-www-form-urlencoded');
    var origin_data = null;


    return this.http.post(url, body, {
        headers: headers
      })
      .map((res: Response) => res.json())
      .subscribe(function (res: Response) {
        let data = res;

        if (typeof callback === 'function') {
          callback(data);
        }
      }.bind(this), function (error) {
        if (errorCallback && typeof errorCallback === 'function')
          errorCallback(error);
      }.bind(this));
  }
  getData(callback = undefined,errorCallback =undefined) {

    var url = 'http://app2.me-to-me.com/api/live/liveTimeline';
    //  var url = 'http://192.168.89.205:8080/api/live/liveTimeline';
    var body = "uid=295&token=76cfdad8ebe94ef9abe6b1e0fa3695e3&appId=110202&topicId=1317&sinceId=0&security={\"appId\":\"100201\",\"currentTime\":\"1471077216791\",\"nonce\":\"043eb17ae3eb4bc09407e63b3bb10a12\",\"sign\":\"aa35ad90185ba7760a9a9bd2b587610af385a761\"}"

    var body_mask = JSON.stringify(body);
    console.info(body_mask)

    var headers = new Headers();
    headers.append('Content-Type', 'application/x-www-form-urlencoded');
    var origin_data = null;


    return this.http.post(url, body, {
        headers: headers
      })
      .map((res: Response) => res.json())
      .subscribe(function (res: Response) {
        let data = res;

        if (typeof callback === 'function') {
          callback(data);
        }
      }.bind(this), function (error) {
        if (errorCallback && typeof errorCallback === 'function')
          errorCallback(error);
      }.bind(this));
  }


}
